package controller;

import model.Account;
import model.Attributes;
import model.Category;
import model.CategoryAttribute;
import model.Currency;
import model.Locations;
import model.Payee;
import model.Project;
import model.TransactionAttribute;
import model.Transactions;

import java.util.List;

import persistence.AccountDAO;
import persistence.AttributesDAO;
import persistence.CategoryAttributeDAO;
import persistence.CategoryDAO;
import persistence.CurrencyDAO;
import persistence.LocationsDAO;
import persistence.PayeeDAO;
import persistence.ProjectDAO;
import persistence.TransactionAttributeDAO;
import persistence.TransactionsDAO;

public class PercistirDados {
	
	public int persistirCurrency(List<Currency> listCurrency ) throws Exception{
		int ret;
		CurrencyDAO dao = new CurrencyDAO();
		dao.deleteAllCurrency();
		ret = dao.insertListCurrency(listCurrency);
		dao = null;
		return ret;
	}
	
	public int persistirAttributes(List<Attributes> listAttributes) throws Exception{
		int retorno;
		AttributesDAO dao = new AttributesDAO();
		dao.deleteAllAttributes();
		retorno = dao.insertListAttributes(listAttributes);
		dao = null;
		return retorno;
	}
	
	public int persistirLocations(List<Locations> listLocations) throws Exception{
		int retorno;
		LocationsDAO dao = new LocationsDAO();
		dao.deleteAllLocations();
		retorno = dao.insertListLocations(listLocations);
		dao = null;
		return retorno;
	}
	
	public int persistirProject(List<Project> listProject) throws Exception{
		int retorno;
		ProjectDAO dao = new ProjectDAO();
		dao.deleteAllProjects();
		retorno = dao.insertListProjects(listProject);
		dao = null;
		return retorno;
	}
	
	public int persistirCategory(List<Category> listCategories) throws Exception{
		int retorno;
		CategoryDAO dao = new CategoryDAO();
		dao.deleteAllCategory();
		retorno = dao.insertListCategory(listCategories);
		dao = null;
		return retorno;
	}
	
	public int persistirAccount(List<Account> listAccount) throws Exception{
		int retorno;
		AccountDAO dao = new AccountDAO();
		dao.deleteAllAccount();
		retorno = dao.insertListAccount(listAccount);
		dao = null;
		return retorno;
	}
	
	public int persistirPayee(List<Payee> listPayee) throws Exception{
		int retorno;
		PayeeDAO dao = new PayeeDAO();
		dao.deleteAllPayee();
		retorno = dao.insertListPayee(listPayee);
		dao = null;
		return retorno;
	}
	
	public int persistirCategoryAttribute(List<CategoryAttribute> listCategoryAttribute) throws Exception{
		int retorno;
		CategoryAttributeDAO dao = new CategoryAttributeDAO();
		dao.deleteAllCategoryAttribute();
		retorno = dao.insertListCategoryAttribute(listCategoryAttribute);
		dao = null;
		return retorno;
	}
	
	public int persistirTransactions(List<Transactions> listTransactions) throws Exception{
		int retorno;
		TransactionsDAO dao = new TransactionsDAO();
		dao.deleteAllTransactions();
		retorno = dao.insertListTransactions(listTransactions);
		dao = null;
		return retorno;
	}
	
	public int persistirTransactionAttribute(List<TransactionAttribute> listTransactionAttribute) throws Exception{
		int retorno;
		TransactionAttributeDAO dao = new TransactionAttributeDAO();
		dao.deleteAllTransactionsAttribute();
		retorno = dao.insertListTransactionsAttribute(listTransactionAttribute);
		dao = null;
		return retorno;
	}
}
